package com.example.demo.util;

import com.example.demo.pojo.Music;

import java.io.File;

public class DeleteFileUtil {
    public static void deleteMusicFile(Music music){
        String imgPath = System.getProperty("user.dir")+
                File.separator+"src"+File.separator+"main"+File.separator + "resources"+File.separator+"static"+File.separator+"img"+File.separator;

        String imgName = music.getImgPath();
        File imgFile = new File(imgPath + imgName);
        if(imgFile.exists()){
            imgFile.delete();
        }

        String musicPath = System.getProperty("user.dir")+
                File.separator+"src"+File.separator+"main"+File.separator + "resources"+File.separator+"static"+File.separator+"mp3"+File.separator;

        String musicName = music.getMusicPath();
        File musicFile = new File(musicPath + musicName);
        if(musicFile.exists()){
            musicFile.delete();
        }

        String lyricPath = System.getProperty("user.dir")+
                File.separator+"src"+File.separator+"main"+File.separator + "resources"+File.separator+"static"+File.separator+"lyric"+File.separator;

        String lyricName = music.getLyricPath();
        File lyricFile = new File(lyricPath + lyricName);
        if(lyricFile.exists()){
            lyricFile.delete();
        }
    }

}
